import gugga.animations.TimeLineAnimation;
import gugga.application.Section;
import gugga.application.SectionsController;
import gugga.common.ITask;
import gugga.sequence.ExecuteMethodTask;
import gugga.sequence.TaskSequence;

/**
 * @author bony
 */
class siteWithSubSections.ContactSection extends SectionsController 
{ 	
	// List the ContactSection fields here.
	
	// Those are the two subsections of the ContactSection. 
	private var mInfoSection:Section;
	private var mInterestSection:Section;
	
	private var mOpenAnimation:TimeLineAnimation;
	private var mCloseAnimation:TimeLineAnimation;
	
	// constructor
	function ContactSection() 
	{
		super();
		
		// Get the instances from the scene.
		mInfoSection = getComponent("InfoSection");
		mInterestSection = getComponent("InterestSection");
		
		mOpenAnimation = getComponent("OpenSection");
		mCloseAnimation = getComponent("CloseSection");
	}

	public function initUI()
	{
		super.initUI();

		// Register the subsections in the ContactSection.		
		registerSubSections();
		
		// Prepare and register section sequences.
		
		// Initialization sequence
		// Using default initialization sequence. 
		
		// Activating sequence
		// Using default activating sequence.
				
		// Open sequence
		// Show section and start open animation 
		var openSequence:TaskSequence = new TaskSequence();
		openSequence = prepareOpeningSequence(); 
		this.registerOpeningTask(openSequence);
		
		// Close sequence
		// Close animation and hide section -  this is behavior we like this section to have.		
		var closeSequence:TaskSequence = new TaskSequence();
		closeSequence = prepareClosingSequence();
		this.registerClosingTask(closeSequence);	
	}
	
	public function registerSubSections():Void
	{
		registerChildSection("InfoSection", "Info", "Info");
		registerChildSection("InterestSection", "Interest", "Interest");	
	}
	
	private function prepareOpeningSequence() : TaskSequence
	{
		// Create task that will show current section - 
		// this task will be included in appropriate place in open sequence. 
		var showTask:ITask = ExecuteMethodTask.create(this, this.show, null);
		
		var openSequence:TaskSequence = new TaskSequence();
		openSequence.addTask(showTask);
		openSequence.addTask(mOpenAnimation);
		
		return openSequence;
	}

	private function prepareClosingSequence() : TaskSequence
	{				
		// Create task that will hide current section - 
		// this task will be included in appropriate place in close sequence. 
		var hideTask:ITask = ExecuteMethodTask.create(this, this.hide, null);
		
		var closeSequence:TaskSequence = new TaskSequence();
		closeSequence.addTask(mCloseAnimation);
		closeSequence.addTask(hideTask);
		
		return closeSequence;
	}
}